﻿namespace DeltaGroup.WheelOfJeopardy.Model
{
    using System;
    using System.Reflection;

    public static class SectorFactory
    {
        #region Methods

        /// <summary>
        /// Creates the sector.
        /// </summary>
        /// <param name="typeName">Name of the type.</param>
        /// <returns></returns>
        public static Sector CreateSector(string typeName)
        {
            Type sectorType = Type.GetType(typeName);
            Sector sector = Activator.CreateInstance(sectorType,
                BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
                null, null, null) as Sector;

            return sector;
        }

        /// <summary>
        /// Creates the sector.
        /// </summary>
        /// <param name="typeName">Name of the type.</param>
        /// <param name="category">The category.</param>
        /// <returns></returns>
        public static Sector CreateSector(string typeName, string category)
        {
            Type sectorType = Type.GetType(typeName);
            Sector sector = Activator.CreateInstance(sectorType,
                BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
                null, new object[] { category }, null) as Sector;

            return sector;
        }

        #endregion Methods
    }
}